package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@Slf4j
public class SendMqController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("sendMq")
    public String sendMq() {
        for (int i = 0; i < 10; i++) {
            OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
            orderReturnReasonEntity.setId(111L);
            orderReturnReasonEntity.setName("嘿嘿222");
            orderReturnReasonEntity.setSort(1122);
            rabbitTemplate.convertAndSend("helloExchange", "helloQueue", orderReturnReasonEntity, new CorrelationData(UUID.randomUUID().toString()));
            log.info("消息发送完成：{}" + orderReturnReasonEntity);
        }
        return "OK";
    }

}
